//
//  StatusCellTopView.swift
//  sinaWeiBo
//
//  Created by smartlei on 15/10/19.
//  Copyright © 2015年 smartlei. All rights reserved.
//

import UIKit

class StatusCellTopView: UIView {

    var  statusViewModel: StatusViewModel? {
        didSet {
            //加载数据
            iconImgView.sd_setImageWithURL(statusViewModel?.profile_image_url)
            screen_nameLable.text = statusViewModel?.status?.user?.screen_name
          
            userVipImageView.image = statusViewModel?.userVipImage
            
            userMemberImageView.image = statusViewModel?.userMemberImage
            
            sourceLable.text =  "北京"
            created_atLable.text = "刚刚刚刚"
        }
    }
    
    //重写父类方法
   override init(frame: CGRect) {
        super.init(frame: frame)
        //
    
        setupUI()
    }
   required init?(coder aDecoder: NSCoder) {
       fatalError("init(coder:) has not been implemented")
   }
    //添加头像控件
    //控件必须指定类型，不然报错
    lazy var  iconImgView: UIImageView = UIImageView(name: "avatar_default_big")
    //添加昵称图标
   // lazy var  screen_nameLable: UILabel = UILabel(labText: "大家一起嗨！",fontSize: 14, textInset: StatusCellMargin)
     lazy var  screen_nameLable: UILabel = UILabel(labText: "tesdddd")
    //添加Vip徽章
    lazy var  userVipImageView: UIImageView  = UIImageView(name: "common_icon_membership_expired")
    //添加认证图标
    lazy var  userMemberImageView: UIImageView = UIImageView(name: "avatar_grassroot")
    
    //添加来源Lable
    lazy var  sourceLable: UILabel = UILabel(labText: "北京大牛",  fontSize: 14)
    //添加微博发布时间
    lazy var  created_atLable: UILabel = UILabel(labText: "刚放", fontSize: 14)
    
    
    
    
    
}
//MARK - 重添加控件并部署控件
extension StatusCellTopView {
    
    //设置UI界面
    private func setupUI() {
        //1 添加控件
        addSubview(iconImgView)
        addSubview(screen_nameLable)
        addSubview(userVipImageView)
        addSubview(userMemberImageView)
        addSubview(sourceLable)
        addSubview(created_atLable)
        
        //2 设置约束
        iconImgView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top).offset(StatusCellMargin)
            make.left.equalTo(self.snp_left).offset(StatusCellMargin)
            make.width.equalTo(StatusCellIconWH)
            make.height.equalTo(StatusCellIconWH)
        }
        
        
        screen_nameLable.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconImgView.snp_top)
            make.left.equalTo(iconImgView.snp_right).offset(StatusCellMargin)
        }
        userVipImageView.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(screen_nameLable.snp_centerY)
            make.left.equalTo(screen_nameLable.snp_right).offset(StatusCellMargin)
        }
        userMemberImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconImgView.snp_right)
            make.centerY.equalTo(iconImgView.snp_bottom)
        }
        sourceLable.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(iconImgView.snp_bottom)
            make.left.equalTo(iconImgView.snp_right).offset(StatusCellMargin)
        }
        created_atLable.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(sourceLable.snp_right).offset(StatusCellMargin)
            make.centerY.equalTo(sourceLable.snp_centerY)
        }
        
        //设置背景颜色
       // backgroundColor = UIColor(white: 237.0/255.0, alpha: 1)
        
        
    }
    
}

